/**
 * 
 */
package any.desktop.gwt.client;

import any.gwt.client.http.AsynClient;
import any.gwt.client.http.AsynClientListener;
import any.gwt.client.http.AsynClient.PreSendProcessor;

import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.URL;

/**
 * TODO: Doc me
 * 
 * @author keke <keke@codehaus.org>
 * @version
 * @revision $Revision:$
 */
public class SearchClient {
    private final AsynClient asynClient = new AsynClient();

    public void addClientListener(final AsynClientListener listener) {
        asynClient.addClientListener(listener);
    }

    public void openItem(final String itemId) {
        asynClient.post("openItem", "/any/desktop/api/item" + itemId + "?open",
                null);
    }

    public void removeClientListener(final AsynClientListener listener) {
        asynClient.removeClientListener(listener);
    }

    public void search(final String query, final int start) {
        asynClient.get("search", URL.encode("/any/desktop/api/search?q="
                + query + "&s=" + start + "&type=json"), null,
                new PreSendProcessor() {

                    public void process(final RequestBuilder requestBuilder) {
                        requestBuilder.setHeader("Accept", "application/json");
                    }
                }, null);
    }
}
